import request from '@/config/axios'

/** CDR信息 */
export interface ECdr {
          callere164: string; // 主叫号码
          calleee164: string; // 被叫号码
          calleeaccesse164: string; // 原始被叫
          callerip: string; // 主叫IP
          callergatewayid: string; // 对接网关
          calleeip: string; // 被叫IP
          calleetogatewaye164: string; // 呼出被叫号码
          starttime: number; // 起始时间
          stoptime: number; // 终止时间
          holdtime: number; // 通话的时长
          flowno: number; // 话单的唯一标识
          enddirection: number; // 挂断方0: 主叫挂断1: 被叫挂断2: 服务器挂断
          phoneTag: string; // 业务标签
  }

// CDR API
export const ECdrApi = {
  // 查询CDR分页
  getECdrPage: async (params: any) => {
    return await request.get({ url: `/vos/E-cdr/page`, params })
  },

  // 查询CDR详情
  getECdr: async (id: number) => {
    return await request.get({ url: `/vos/E-cdr/get?id=` + id })
  },

  // 新增CDR
  createECdr: async (data: ECdr) => {
    return await request.post({ url: `/vos/E-cdr/create`, data })
  },

  // 修改CDR
  updateECdr: async (data: ECdr) => {
    return await request.put({ url: `/vos/E-cdr/update`, data })
  },

  // 删除CDR
  deleteECdr: async (id: number) => {
    return await request.delete({ url: `/vos/E-cdr/delete?id=` + id })
  },

  /** 批量删除CDR */
  deleteECdrList: async (ids: number[]) => {
    return await request.delete({ url: `/vos/E-cdr/delete-list?ids=${ids.join(',')}` })
  },

  // 导出CDR Excel
  exportECdr: async (params: any, timeout = 1200000) => {
    return await request.download({
      url: `/vos/E-cdr/export-excel`,
      params,
      timeout // ✅ 只放大这一个请求的超时
    })
  },
}
